package com.psytech.app.task.entity.implementation;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * The persistent class for the user database table.
 */
@Entity
@Table(name = "`user`")
public class User implements Serializable, STMEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4914812679331527428L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;

	private String uid;

	private String firstname;

	private String lastname;

	private String nickname;

	private String password;

	private String login;

	// bi-directional many-to-one association to Task
	@OneToMany(mappedBy = "creator", targetEntity = Task.class)
	private List<Task> createdTasks;

	// bi-directional many-to-many association to Task
	@ManyToMany(mappedBy = "users")
	private List<Task> affectedTasks;

	@OneToMany(mappedBy = "writer", targetEntity = Comment.class)
	private List<Comment> comments;

	public User() {
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(final Integer id) {
		this.id = id;
	}

	/**
	 * A définir par la couche métier.
	 * 
	 * @param uid
	 *            Universal ID de la tâche.
	 */
	public String getUid() {
		return this.uid;
	}

	public void setUid(final String uid) {
		this.uid = uid;
	}

	public String getFirstname() {
		return this.firstname;
	}

	public void setFirstname(final String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return this.lastname;
	}

	public void setLastname(final String lastname) {
		this.lastname = lastname;
	}

	public String getNickname() {
		return this.nickname;
	}

	public void setNickname(final String nickname) {
		this.nickname = nickname;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(final String password) {
		this.password = password;
	}

	public List<Task> getCreatedTasks() {
		if (this.createdTasks == null)
			this.createdTasks = new ArrayList<Task>();
		return this.createdTasks;
	}

	public void setCreatedTasks(final List<Task> createdTasks) {
		this.createdTasks = createdTasks;
	}

	public List<Task> getAffectedTasks() {
		if (this.affectedTasks == null)
			this.affectedTasks = new ArrayList<Task>();
		return this.affectedTasks;
	}

	public void setAffectedTasks(final List<Task> affectedTasks) {
		this.affectedTasks = affectedTasks;
	}

	public String getLogin() {
		return this.login;
	}

	public void setLogin(final String login) {
		this.login = login;
	}

	public List<Comment> getComments() {
		if (this.comments == null)
			this.comments = new ArrayList<Comment>();
		return this.comments;
	}

	public void setComments(final List<Comment> comments) {
		this.comments = comments;
	}

	@Override
	public String toString() {
		return "LastName => " + this.getLastname() + ", FirstName => " + this.getFirstname() + ", Uid => " + this.getUid() + ", Id => " + this.getId();
	}

}